package pmsjc.dpi.psaudavel;

import java.util.ArrayList;
import pmsjc.dpi.psaudavel.R;

import pmsjc.dpi.locatend.classes.*;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Spinner;
import android.widget.TextView;

public class SimpleAdapter extends BaseAdapter {

	  private static final String TAG = "SimpleAdapter";
		private LayoutInflater mInflater;
	    private ArrayList<locatend> itens;
	    private int layoutPostos = 0;
	    
	    public SimpleAdapter(Context context, ArrayList<locatend> itens,int lay){
			//Itens que preencheram o listview
	        this.itens = itens;
	        //responsavel por pegar o Layout do item.
	        mInflater = LayoutInflater.from(context);
	        layoutPostos = lay;
		}
		
		@Override
		public int getCount() {
			return itens.size();
		}

		@Override
		public Object getItem(int position) {
			return  itens.get(position);
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View view, ViewGroup parent) {
	        //Pega o item de acordo com a posção.
			locatend item = itens.get(position);
	        //infla o layout para podermos preencher os dados
	        view = mInflater.inflate(layoutPostos, null);

	        //atravez do layout pego pelo LayoutInflater, pegamos cada id relacionado
	        //ao item e definimos as informações.
	       // Log.i(TAG, "item.getLoc_descricao():"+item.getLoc_descricao());
	       
	        //TextView tvDesc = (TextView) view.findViewById(R.unidades.tipo);
			//TextView tvDesc = (TextView) view.findViewById(R.layout.roteiro);
			
			Spinner spnRoteiro = (Spinner)view.findViewById(R.id.spnRoteiro);
			
			//tvDesc.setMovementMethod(LinkMovementMethod.getInstance());
	       // String text = "<a href='"+item.getLoc_link().toString()+"'>"+item.getLoc_descricao().toString()+"</a>";
			//tvDesc.setText(Html.fromHtml(text));
			//tvDesc.setText(item.getLocal_roteiro().toString());
			
			//jmt: pattern we want to match and turn into a clickable link
			//Pattern pattern = Pattern.compile(item.getLoc_link().toString());
			//jmt: prefix our pattern with http://
			//Linkify.addLinks(tvDesc, pattern, "http://");
	        
	        return view; 

		}

	}
